<?php

namespace App\Models;

use App\Models\BaseModel;

class HhmMember extends BaseModel
{
    protected $table = 'ims_hhm_member';
    
    protected $primaryKey = 'id';
    
    public $incrementing = true;
    
    public $timestamps = false;
    
    protected $fillable = [
        'uniacid',
        'openid',
        'mobile',
        'password',
        'nickname',
        'avatar',
        'union_id',
        'gender',
        'created_at',
        'updated_at',
    ];
    
    
    /**
     * 添加数据并返回id
     *
     * @param $userinfo
     * @param $uniacid
     * @return mixed
     */
    public static function insertData($userinfo, $uniacid)
    {
        $member_model = new HhmMember();

        $member_model->uniacid = $uniacid;
        $member_model->openid = $userinfo['openid'] ?? '';
        $member_model->nickname = stripslashes($userinfo['nickname'] ?? '');
        $member_model->avatar = $userinfo['headimgurl'] ?? '';
        $member_model->gender = $userinfo['sex'] ?? 0;
        $member_model->created_at = time();
        $member_model->updated_at = time();

        if ($member_model->save()) {
            return $member_model;
        } else {
            return false;
        }
    }

       /**
     * 更新数据
     *
     * @param $uid
     * @param $data
     * @return mixed
     */
    public static function updataData($uid, $data)
    {
        return self::uniacid()
            ->where('uid', $uid)
            ->update($data);
    }
}